﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class CMD_EmployeeInfo : System.Web.UI.UserControl
    {
        private IMovmentBLL movBLL = new MovmentBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //    bindMovmentCombo();
        }

        public void bindMovmentCombo()
        {
            IList<MovmentInfo> infoList = movBLL.ListMovments(Session["EMPTYPE"].ToString());

            movmentCombo.DataSource = infoList;
            movmentCombo.DataBind();
        }
        protected void btnFindTempEmployee_Load(object sender, EventArgs e)
        {
            //if (DataItem is Telerik.Web.UI.GridInsertionObject)
            //{
                btnFindTempEmployee.Attributes.Add("OnClick", "LinkMDdetail(" + HideTempEmployee.ClientID + "," + "'Forms/DialogRC_TmpEmp.aspx','../frmIframe.html',700,500)");
            //}
        }

        protected void btnFindTempEmployee_Click(object sender, ImageClickEventArgs e)
        {
            txttempEmployee.Text = "";
            lblBirthDate.Text = "";
            lblCitizen.Text = "";

            string st = HideTempEmployee.Value;
            if (st == "")
                return;

            lblTmpEmpSeq.Text = st;

            RecruitNewEmployeeBLL obj = new RecruitNewEmployeeBLL();

            DataRowCollection dr;
            dr = obj.SelectTmpEmployee(Int32.Parse(st), (int?)null, (int?)null).Rows;
            if (dr.Count > 0)
            {
                txttempEmployee.Text = dr[0]["full_name"].ToString();
                lblBirthDate.Text = string.Format("{0:dd/MM/yyyy}", dr[0]["birth_date"]);//  .ToString("dd/MM/yyyy", new CultureInfo("th-TH"));
                lblCitizen.Text = dr[0]["citizen"].ToString();
            }
        }
        public void bindTmpEducateCombo()
        {
            RecruitNewEmployeeBLL empBLL = new RecruitNewEmployeeBLL();
            DataTable dataTable = new DataTable();

            dataTable = empBLL.SelectTmpEducation(int.Parse(lblTmpEmpSeq.Text));

            foreach (DataRow dataRow in dataTable.Rows)
            {
                RadComboBoxItem item = new RadComboBoxItem();

                item.Text = (string)dataRow["edu_qual_name"]
                        + " สาขาวิชา"
                        + (string)dataRow["edu_major_name"]
                        + " "
                        + (string)dataRow["edu_ins_name"];
                item.Value = dataRow["tmp_edu_seq"].ToString();

                item.Attributes.Add("degree", (string)dataRow["edu_degree_name"]);
                item.Attributes.Add("qualification", (string)dataRow["edu_qual_name"]);
                item.Attributes.Add("major", (string)dataRow["edu_major_name"]);
                item.Attributes.Add("institutes", (string)dataRow["edu_ins_name"]);

                cmbTmpEdu.Items.Add(item);

                item.DataBind();
            }
        }   
        protected void cmbTmpEdu_ItemsRequested(object o, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
        {
            bindTmpEducateCombo();
        }

        protected void movmentCombo_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            bindMovmentCombo();
        }
    }
}